import dayjs from 'dayjs'
import dataQueryApi from '@/api/modules/data.query'

export function useErrHook(produceData: any, startTime: any, endTime: any) {
  const errorTime = reactive<any>([])

  function getErrorData() {
    return dataQueryApi.GetReuseEx({
      objIDs: [unref(produceData).ObjID],
      startTime: unref(startTime),
      endTime: unref(endTime),
    }).then(
      (res) => {
        const { Items } = res as any
        Items.forEach((item: any) => {
          errorTime.push([
            {
              xAxis: dayjs(item.StartTime).format('YYYY-MM-DD HH:mm'),
              itemStyle: {
                color: 'rgba(255, 173, 177, 0.4)',
              },
            },
            {
              xAxis: item.EndTime
                ? dayjs(item.EndTime).format('YYYY-MM-DD HH:mm')
                : dayjs().format('YYYY-MM-DD HH:mm:ss'),
              itemStyle: {
                color: 'rgba(255, 173, 177, 0.4)',
              },
            },
          ])
        })
      },
    )
  }

  return { errorTime, getErrorData }
}
